@extends('app')

@section('content')
<link rel="stylesheet" type="text/css" href="{{ asset('/jquery-date/dateRange.css') }}" />
<script src="{{ asset('/jquery-date/dateRange.js') }}" type="text/javascript"></script>


<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="tabbable" id="tabs-876069">
                <ul class="nav nav-tabs">
                    <li class="active">
                        <a href="{{ url('/admin/enterprise/questions')}}">题库管理</a>
                    </li>
                    <li>
                        <a href="{{ url('/admin/enterprise/questions/create')}}">添加</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <!--列表开始-->
                    <div class="panel panel-default mt20">
                        <div class="table-responsive panel-body">
                        <table class="table table-hover">
                            <thead>
                              <tr>
                                <th>编号</th>
                                <th>标题</th>
                                <th>答案</th>
                                <th>解释</th>
                                <th>题型</th>
                                <th>所属企业</th>
                                <th>操作</th>
                              </tr>
                            </thead>
                            <tbody>
                            @foreach($questions as $res)

                                <tr id="news_{{ $res->id }}">
                                  <td>{{ $res->id }}</td>
                                  <td>
                                    <span>
                                      {{ $res->title }}
                                    </span>
                                  </td>
                                  <td>
                                      <span style="color: #2ECC71;" >
                                        {!! $res->answer !!}
                                      </span>
                                  </td>
                                  <td>
                                      <span class=" " style="">
                                        {{ str_limit($res->explain,25) }}
                                      </span>
                                  </td>
                                  <td>
                                      <span style="color: #2ECC71;cursor: pointer;" >
                                        @if ($res->questions_type == 0)
                                          单选
                                        @else
                                          多选
                                        @endif
                                      </span>
                                  </td>
                                  <td>
                                      <span>
                                        {{ count($res->getCompanyInfo)>0?$res->getCompanyInfo->name:'系统试题' }}
                                      </span>
                                  </td>
                                  <td>
                                    <a href="{{ url('/admin/enterprise/questions/'.$res->id.'/edit') }}"><i class="glyphicon glyphicon-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:void(0);" onclick="delete_one('/admin/enterprise/questions/{{$res->id}}',{{$res->id}},'{{ csrf_token() }}')"><i class="glyphicon glyphicon-remove-sign"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                  </td>
                                </tr>
                            @endforeach
                            </tbody>
                          </table>
                        </div>
                        <div>{!! $questions->render() !!} </div>
                    </div>
                    <!--列表结束-->
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
  // 鼠标滑过出现提示
  $(function () {
    $('[data-toggle="tooltip"]').tooltip();

    // 初始化 隐藏域的日期参数
    $('input[name="auth_at_start"]').val(start);
    $('input[name="auth_at_end"]').val(end);
  })

  // 日期选择
  var start = showTime(-1); //当前日期前1天日期
  var end = showTime(1); //当前日期
  var dateRange1 = new pickerDateRange('date1', {
                aToday : 'aToday',
                isTodayValid: false,
                startDate: start,
                endDate: end,
                needCompare: false,
                defaultText: ' 至 ',
                autoSubmit: true,
                inputTrigger: 'input_trigger1',
                theme: 'ta',
                success: function (obj) {
                    $("#dCon2").html('开始时间 : ' + obj.startDate + '<br/>结束时间 : ' + obj.endDate);
                    $('input[name="auth_at_start"]').val(obj.startDate);
                    $('input[name="auth_at_end"]').val(obj.endDate);
                }
            });


/*=========================处理当前时间的前几天日期======================================*/
 function addByTransDate(dateParameter, num) {
    var translateDate = "", dateString = "", monthString = "", dayString = "";
    translateDate = dateParameter.replace("-", "/").replace("-", "/");
    var newDate = new Date(translateDate);
    newDate = newDate.valueOf();
    newDate = newDate + num * 24 * 60 * 60 * 1000;
    newDate = new Date(newDate);
    //如果月份长度少于2，则前加 0 补位
    if ((newDate.getMonth() + 1).toString().length == 1) {
      monthString = 0 + "" + (newDate.getMonth() + 1).toString();
    } else {
      monthString = (newDate.getMonth() + 1).toString();
    }
    //如果天数长度少于2，则前加 0 补位
    if (newDate.getDate().toString().length == 1) {
      dayString = 0 + "" + newDate.getDate().toString();
    } else {
      dayString = newDate.getDate().toString();
    }
    dateString = newDate.getFullYear() + "-" + monthString + "-" + dayString;
    return dateString;
}

function reduceByTransDate(dateParameter, num) {
  var translateDate                              = "", dateString = "", monthString = "", dayString = "";
  translateDate                                  = dateParameter.replace("-", "/").replace("-", "/");
  var newDate                                    = new Date(translateDate);
  newDate                                        = newDate.valueOf();
  newDate                                        = newDate - num * 24 * 60 * 60 * 1000;
  newDate                                        = new Date(newDate);
  //如果月份长度少于2，则前加 0 补位
  if ((newDate.getMonth() + 1).toString().length == 1) {
    monthString                                    = 0 + "" + (newDate.getMonth() + 1).toString();
  } else {
    monthString                                    = (newDate.getMonth() + 1).toString();
  }
  //如果天数长度少于2，则前加 0 补位
  if (newDate.getDate().toString().length        == 1) {
    dayString                                      = 0 + "" + newDate.getDate().toString();
  } else {
    dayString                                      = newDate.getDate().toString();
  }
  dateString                                     = newDate.getFullYear() + "-" + monthString + "-" + dayString;
  return dateString;
}

//得到日期  主方法
    function showTime(pdVal) {
      var trans_day  = "";
      var cur_date   = new Date();
      var cur_year   = cur_date.getFullYear();
      var cur_month  = cur_date.getMonth() + 1;
      var real_date  = cur_date.getDate();
      cur_month      = cur_month > 9 ? cur_month : ("0" + cur_month);
      real_date      = real_date > 9 ? real_date : ("0" + real_date);
      eT             = cur_year + "-" + cur_month + "-" + real_date;
      if (pdVal      == 1) {
        trans_day      = addByTransDate(eT, 1);
      }
      else if (pdVal == -1) {
        trans_day      = reduceByTransDate(eT, 1);
      }
      else {
        trans_day      = eT;
      }
      //处理
      return trans_day;
    }

/*=========================处理当前时间的前几天日期  end======================================*/
</script>
@endsection
